//
//  Example4ViewController.m
//  Example4
//
//  Created by Benjamin Mort on 27/06/2012.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "Example4ViewController.h"

@implementation Example4ViewController

@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize button;

// Methods

// Main control action method
-(IBAction) mainControlSwitched:(id)sender
{
    // Segment 0 or 1 selection logic
    if ([sender selectedSegmentIndex] == 0) 
    {
        leftSwitch.hidden = NO;
        rightSwitch.hidden = NO;
        button.hidden = YES;
    }
    else 
    {
        leftSwitch.hidden = YES;
        rightSwitch.hidden = YES;
        button.hidden = NO;        
    }
}


// Switch changed method
-(IBAction) switchChanged:(id)sender
{
    UISwitch *mySwitch = (UISwitch*) sender;
    BOOL yn = mySwitch.isOn;
    [leftSwitch setOn:yn animated:YES];
    [rightSwitch setOn:yn animated:YES];
}


// Button pressed method
-(IBAction) buttonPressed
{
    // Create an action sheet.
    // we will put the delegate in this class so delegate = self
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"Want to see an alert?"
                                  delegate:self
                                  cancelButtonTitle:@"cancel"
                                  destructiveButtonTitle:@"Yea, lets see it!"
                                  otherButtonTitles:nil];

    // show the action sheet.
    [actionSheet showInView:self.view];
    
    // Free up the memory
    [actionSheet release];
}

// Action sheet method to run on yes see it action
-(void)actionSheet: (UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
{
    // If not cancel button
    if (buttonIndex != [actionSheet cancelButtonIndex])
    {
        // Do something: Create an alert.
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"OK, here it is" 
                              message:@"Bacon is good ummm"
                              delegate:nil
                              cancelButtonTitle:@"Done"
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
    [leftSwitch release];
    [rightSwitch release];
    [button release];
    [super dealloc];
}

@end
